﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using BUS;
using Common;
using Microsoft.Ajax.Utilities;

public partial class Pages_PostEntry : System.Web.UI.Page
{
    BUS_WRCATEGORYLV1 busWrcategorylv1 = new BUS_WRCATEGORYLV1();
    BUS_WRAREA busWrarea = new BUS_WRAREA();
    BUS_WRREGION busWrregion = new BUS_WRREGION();
    BUS_WRCITY busWrcity = new BUS_WRCITY();
    BUS_WRENTRY busWrentry = new BUS_WRENTRY();
    BUS_WRMEDIASTORE busWrmediastore = new BUS_WRMEDIASTORE();
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.MaintainScrollPositionOnPostBack = true;
        if (!IsPostBack)
        {
            //if(Session["City"].ToString() == "-1")
            //    Response.Redirect("~/Pages/Location.aspx");
            BindDrop();
        }
    }

    private void BindDrop()
    {
        ddlCategoryLv1.DataSource = busWrcategorylv1._GetList().Select(p => new
        {
            p.ID,
            p.CategoryLv1Name
        }).ToList();
        ddlCategoryLv1.DataTextField = "CategoryLv1Name";
        ddlCategoryLv1.DataValueField = "ID";
        ddlCategoryLv1.DataBind();

        ddlArea.DataSource = busWrarea._GetList().Select(p => new
        {
            p.ID,
            p.AreaName
        }).ToList();
        ddlArea.DataTextField = "AreaName";
        ddlArea.DataValueField = "ID";
        ddlArea.DataBind();
        ddlArea.Items.Insert(0, new ListItem("---Select----", ""));
        ddlArea.SelectedIndex = 0;

        if (Session["Area"].ToString() != "-1")
        {
            ddlArea.SelectedValue = Session["Area"].ToString();
            ddlRegion.Items.Clear();
            ddlCity.Items.Clear();

            ddlRegion.DataSource = busWrregion._GetList().Where(q => q.IDArea == Int32.Parse(ddlArea.SelectedValue)).Select(p => new
            {
                p.ID,
                p.RegionName
            }).ToList();
            ddlRegion.DataTextField = "RegionName";
            ddlRegion.DataValueField = "ID";
            ddlRegion.DataBind();
            ddlRegion.Items.Insert(0, new ListItem("---Select----", ""));
            ddlRegion.SelectedIndex = 0;

            if (Session["Region"].ToString() != "-1")
            {
                ddlRegion.SelectedValue = Session["Region"].ToString();
                ddlCity.Items.Clear();

                ddlCity.DataSource = busWrcity._GetList().Where(q => q.IDRegion == Int32.Parse(ddlRegion.SelectedValue)).Select(p => new
                {
                    p.ID,
                    p.CityName
                }).ToList();
                ddlCity.DataTextField = "CityName";
                ddlCity.DataValueField = "ID";
                ddlCity.DataBind();
                ddlCity.Items.Insert(0, new ListItem("---Select----", ""));
                ddlCity.SelectedIndex = 0;

                if (Session["City"].ToString() != "-1")
                {
                    ddlRegion.SelectedValue = Session["City"].ToString();
                }
            }
        }
    }
    protected void btnPost_Click(object sender, EventArgs e)
    {
        string s = Validate();
        if (s.Equals(""))
        {
            int idEntry = 0;
            WRENTRY entry = new WRENTRY();
            entry.EntryName = txtEntryName.Text;
            entry.EntContent = txtEntryContent.Text;
            entry.CreateDate = DateTime.Now;
            entry.IDCreateBy = Int32.Parse(Session["userid"].ToString());
            entry.UpdateDate = (DateTime?) null;
            entry.IDUpdateBy = (int?) null;
            entry.Viewed = 0;
            entry.Price = decimal.Parse(txtPrice.Text);
            entry.PriceDesc = "";
            entry.IDPriceType = rbtDeal.Checked == true ? 1 : 2;
            entry.NameToContact = txtName.Text;
            entry.EmailToContact = txtEmail.Text;
            entry.PhoneToContact = txtPhone.Text;
            entry.AddressToContact = txtAddress.Text;
            entry.IDUrgent = 2;//2: normal, 1: urgent
            entry.UrgenFromDate = (DateTime?) null;
            entry.UrgentToDate = (DateTime?) null;
            entry.UrgentStatus = "N";
            entry.IDCategoryLv = Int32.Parse(ddlCategoryLv1.SelectedValue);
            entry.IDCity = Int32.Parse(ddlCity.SelectedValue);
            if (rbtBuy.Checked == true)
                entry.IDEntType = 1;
            else if (rbtSale.Checked == true)
            {
                entry.IDEntType = 2;
            }
            else
            {
                entry.IDEntType = 3;
            }
            entry.IDSaleType = rbtPerson.Checked == true ? 2 : 1;
            entry.IDUserApprove = (int?) null;
            entry.Active = "N";
            entry.Keywords = str_replace_alias(txtEntryName.Text);
            //entry.IDCity = Int32.Parse(Session["City"].ToString());
            busWrentry._Add(entry,ref idEntry,true);
            if (idEntry >0)
            {
                insertWRMEDIASTORE(idEntry);
            }
            Response.Redirect("~/Pages/View.aspx");
        }
        else
        {
            WebMsgBox.Show(s);
        }

    }

    public string str_replace(string key)
    {
        string keys = key.ToString();
        keys = keys.Replace(",", "");
        keys = keys.Replace("@", "");
        keys = keys.Replace("#", "");
        keys = keys.Replace("/", "");
        keys = keys.Replace("|", "");
        keys = keys.Replace("*", "");
        keys = keys.Replace("-", "");
        keys = keys.Replace("+", "");
        keys = keys.Replace(".", "");
        keys = keys.Replace("!", "");
        keys = keys.Replace("'", "");
        keys = keys.Replace("?", "");
        //---------------------------------a^
        keys = keys.Replace("ấ", "a");
        keys = keys.Replace("ầ", "a");
        keys = keys.Replace("ẩ", "a");
        keys = keys.Replace("ẫ", "a");
        keys = keys.Replace("ậ", "a");
        //---------------------------------A^
        keys = keys.Replace("Ấ", "A");
        keys = keys.Replace("Ầ", "A");
        keys = keys.Replace("Ẩ", "A");
        keys = keys.Replace("Ẫ", "A");
        keys = keys.Replace("Ậ", "A");
        //---------------------------------a(
        keys = keys.Replace("ắ", "a");
        keys = keys.Replace("ằ", "a");
        keys = keys.Replace("ẳ", "a");
        keys = keys.Replace("ẵ", "a");
        keys = keys.Replace("ặ", "a");
        //---------------------------------A(
        keys = keys.Replace("Ắ", "A");
        keys = keys.Replace("Ằ", "A");
        keys = keys.Replace("Ẳ", "A");
        keys = keys.Replace("Ẵ", "A");
        keys = keys.Replace("Ặ", "A");
        //---------------------------------a
        keys = keys.Replace("á", "a");
        keys = keys.Replace("à", "a");
        keys = keys.Replace("ả", "a");
        keys = keys.Replace("ã", "a");
        keys = keys.Replace("ạ", "a");
        keys = keys.Replace("â", "a");
        keys = keys.Replace("ă", "a");
        //---------------------------------A
        keys = keys.Replace("Á", "A");
        keys = keys.Replace("À", "A");
        keys = keys.Replace("Ả", "A");
        keys = keys.Replace("Ã", "A");
        keys = keys.Replace("Ạ", "A");
        keys = keys.Replace("Â", "A");
        keys = keys.Replace("Ă", "A");
        //---------------------------------e^
        keys = keys.Replace("ế", "e");
        keys = keys.Replace("ề", "e");
        keys = keys.Replace("ể", "e");
        keys = keys.Replace("ễ", "e");
        keys = keys.Replace("ệ", "e");
        //---------------------------------E^
        keys = keys.Replace("Ế", "E");
        keys = keys.Replace("Ề", "E");
        keys = keys.Replace("Ể", "E");
        keys = keys.Replace("Ễ", "E");
        keys = keys.Replace("Ệ", "E");
        //---------------------------------e
        keys = keys.Replace("é", "e");
        keys = keys.Replace("è", "e");
        keys = keys.Replace("ẻ", "e");
        keys = keys.Replace("ẽ", "e");
        keys = keys.Replace("ẹ", "e");
        keys = keys.Replace("ê", "e");
        //---------------------------------E
        keys = keys.Replace("É", "E");
        keys = keys.Replace("È", "E");
        keys = keys.Replace("Ẻ", "E");
        keys = keys.Replace("Ẽ", "E");
        keys = keys.Replace("Ẹ", "E");
        keys = keys.Replace("Ê", "E");
        //---------------------------------i
        keys = keys.Replace("í", "i");
        keys = keys.Replace("ì", "i");
        keys = keys.Replace("ỉ", "i");
        keys = keys.Replace("ĩ", "i");
        keys = keys.Replace("ị", "i");
        //---------------------------------I
        keys = keys.Replace("Í", "I");
        keys = keys.Replace("Ì", "I");
        keys = keys.Replace("Ỉ", "I");
        keys = keys.Replace("Ĩ", "I");
        keys = keys.Replace("Ị", "I");
        //---------------------------------o^
        keys = keys.Replace("ố", "o");
        keys = keys.Replace("ồ", "o");
        keys = keys.Replace("ổ", "o");
        keys = keys.Replace("ỗ", "o");
        keys = keys.Replace("ộ", "o");
        //---------------------------------O^
        keys = keys.Replace("Ố", "O");
        keys = keys.Replace("Ồ", "O");
        keys = keys.Replace("Ổ", "O");
        keys = keys.Replace("Ô", "O");
        keys = keys.Replace("Ộ", "O");
        //---------------------------------o*
        keys = keys.Replace("ớ", "o");
        keys = keys.Replace("ờ", "o");
        keys = keys.Replace("ở", "o");
        keys = keys.Replace("ỡ", "o");
        keys = keys.Replace("ợ", "o");
        //---------------------------------O*
        keys = keys.Replace("Ớ", "O");
        keys = keys.Replace("Ờ", "O");
        keys = keys.Replace("Ở", "O");
        keys = keys.Replace("Ỡ", "O");
        keys = keys.Replace("Ợ", "O");
        //---------------------------------u*
        keys = keys.Replace("ứ", "u");
        keys = keys.Replace("ừ", "u");
        keys = keys.Replace("ử", "u");
        keys = keys.Replace("ữ", "u");
        keys = keys.Replace("ự", "u");
        //---------------------------------U*
        keys = keys.Replace("Ứ", "U");
        keys = keys.Replace("Ừ", "U");
        keys = keys.Replace("Ử", "U");
        keys = keys.Replace("Ữ", "U");
        keys = keys.Replace("Ự", "U");
        //---------------------------------y
        keys = keys.Replace("ý", "y");
        keys = keys.Replace("ỳ", "y");
        keys = keys.Replace("ỷ", "y");
        keys = keys.Replace("ỹ", "y");
        keys = keys.Replace("ỵ", "y");
        //---------------------------------Y
        keys = keys.Replace("Ý", "Y");
        keys = keys.Replace("Ỳ", "Y");
        keys = keys.Replace("Ỷ", "Y");
        keys = keys.Replace("Ỹ", "Y");
        keys = keys.Replace("Ỵ", "Y");
        //---------------------------------DD
        keys = keys.Replace("Đ", "D");
        keys = keys.Replace("Đ", "D");
        keys = keys.Replace("đ", "d");
        //---------------------------------o
        keys = keys.Replace("ó", "o");
        keys = keys.Replace("ò", "o");
        keys = keys.Replace("ỏ", "o");
        keys = keys.Replace("õ", "o");
        keys = keys.Replace("ọ", "o");
        keys = keys.Replace("ô", "o");
        keys = keys.Replace("ơ", "o");
        //---------------------------------O
        keys = keys.Replace("Ó", "O");
        keys = keys.Replace("Ò", "O");
        keys = keys.Replace("Ỏ", "O");
        keys = keys.Replace("Õ", "O");
        keys = keys.Replace("Ọ", "O");
        keys = keys.Replace("Ô", "O");
        keys = keys.Replace("Ơ", "O");
        //---------------------------------u
        keys = keys.Replace("ú", "u");
        keys = keys.Replace("ù", "u");
        keys = keys.Replace("ủ", "u");
        keys = keys.Replace("ũ", "u");
        keys = keys.Replace("ụ", "u");
        keys = keys.Replace("ư", "u");
        //---------------------------------U
        keys = keys.Replace("Ú", "U");
        keys = keys.Replace("Ù", "U");
        keys = keys.Replace("Ủ", "U");
        keys = keys.Replace("Ũ", "U");
        keys = keys.Replace("Ụ", "U");
        keys = keys.Replace("Ư", "U");
        //---------------------------------     
        return keys;
    }

    public string str_replace_alias(string key)
    {
        string result = "";
        result = str_replace(key.Trim()).ToLower().Replace(" ", "-");
        return result;
    }
    
    private string UploadPic0()
    {
        HttpPostedFile files = image_0.PostedFile;
        if (image_0.HasFile == false || files.ContentLength > 500000)
        {
            return "fail";
        }
        else
        {
            string _fileExt = Path.GetExtension(image_0.FileName);
            if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".png" || _fileExt.ToLower() == ".bmp" ||
                _fileExt.ToLower() == ".jpeg" || _fileExt.ToLower() == ".jpg")
            {
                try
                {
                    string filePath = "~/Images/Pic/" + DateTime.Now.Ticks.ToString() + "_" + Session["userid"].ToString() + _fileExt;
                    image_0.SaveAs(Server.MapPath(filePath));
                    return filePath;
                }
                catch
                {
                    return "fail";
                }
            }
            else
            {
                return"fail";
            }
        }
    }
    private string UploadPic1()
    {
        HttpPostedFile files = image_1.PostedFile;
        if (image_1.HasFile == false || files.ContentLength > 500000)
        {
            return "fail";
        }
        else
        {
            string _fileExt = Path.GetExtension(image_1.FileName);
            if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".png" || _fileExt.ToLower() == ".bmp" ||
                _fileExt.ToLower() == ".jpeg" || _fileExt.ToLower() == ".jpg")
            {
                try
                {
                    string filePath = "~/Images/Pic/" + DateTime.Now.Ticks.ToString() + "_" + Session["userid"].ToString() + _fileExt;
                    image_1.SaveAs(Server.MapPath(filePath));
                    return filePath;
                }
                catch
                {
                    return "fail";
                }
            }
            else
            {
                return "fail";
            }
        }
    }
    private string UploadPic2()
    {
        HttpPostedFile files = image_2.PostedFile;
        if (image_2.HasFile == false || files.ContentLength > 500000)
        {
            return "fail";
        }
        else
        {
            string _fileExt = Path.GetExtension(image_2.FileName);
            if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".png" || _fileExt.ToLower() == ".bmp" ||
                _fileExt.ToLower() == ".jpeg" || _fileExt.ToLower() == ".jpg")
            {
                try
                {
                    string filePath = "~/Images/Pic/" + DateTime.Now.Ticks.ToString() + "_" + Session["userid"].ToString() + _fileExt;
                    image_2.SaveAs(Server.MapPath(filePath));
                    return filePath;
                }
                catch
                {
                    return "fail";
                }
            }
            else
            {
                return "fail";
            }
        }
    }
    private string UploadPic3()
    {
        HttpPostedFile files = image_3.PostedFile;
        if (image_3.HasFile == false || files.ContentLength > 500000)
        {
            return "fail";
        }
        else
        {
            string _fileExt = Path.GetExtension(image_3.FileName);
            if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".png" || _fileExt.ToLower() == ".bmp" ||
                _fileExt.ToLower() == ".jpeg" || _fileExt.ToLower() == ".jpg")
            {
                try
                {
                    string filePath = "~/Images/Pic/" + DateTime.Now.Ticks.ToString() + "_" + Session["userid"].ToString() + _fileExt;
                    image_3.SaveAs(Server.MapPath(filePath));
                    return filePath;
                }
                catch
                {
                    return "fail";
                }
            }
            else
            {
                return "fail";
            }
        }
    }
    private string Validate()
    {
        if (ddlCategoryLv1.Text.Trim() == string.Empty)
        {
            return "Category is required";
        }
        if (ddlArea.SelectedValue == string.Empty)
        {
            return "Area is required";
        }
        if (ddlRegion.SelectedValue == string.Empty)
        {
            return "Region is required";
        }
        if (ddlCity.SelectedValue == string.Empty)
        {
            return "City is required";
        }
        if (txtEntryName.Text.Trim() == string.Empty)
        {
            return "Entry name is required";
        }
        if (txtEntryContent.Text.Trim() == string.Empty)
        {
            return "Entry content is required";
        }
        if (!Common.Common.IsNumeric(txtPrice.Text.Trim()))
        {
            return "Price is a number";
        }
        if (txtPrice.Text.Trim() == string.Empty)
        {
            return "Entry name is required";
        }
        if (Session["userid"].ToString().Equals(""))
        {
            return "You must login to post entry";
        }
        if (txtName.Text.Trim() == string.Empty)
        {
            return "Your name is required";
        }
        if (txtEmail.Text.Trim() == string.Empty)
        {
            return " Your e-mail is required";
        }
        if (txtPhone.Text.Trim() == string.Empty)
        {
            return "Your phone is required";
        }
        if (!Common.Common.IsNumeric(txtPhone.Text.Trim()))
        {
            return "Phone is a number";
        }
        if (txtPhone.Text.Length < 8 || txtPhone.Text.Length > 15)
            return "Your phone number between 9 - 15 character";
        if (txtAddress.Text.Trim() == string.Empty)
        {
            return "Your address is required";
        }
        return "";
    }

    private void insertWRMEDIASTORE(int idEntry)
    {
        string s = "";
        HttpPostedFile files0 = image_0.PostedFile;
        if (image_0.HasFile == false || files0.ContentLength > 500000)
        {
        }
        else
        {
            string _fileExt = Path.GetExtension(image_0.FileName);
            if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".png" || _fileExt.ToLower() == ".bmp" ||
                _fileExt.ToLower() == ".jpeg" || _fileExt.ToLower() == ".jpg")
            {
                try
                {
                    string filePath = "~/Images/Pic/" + DateTime.Now.Ticks.ToString() + "_" + Session["userid"].ToString() + _fileExt;
                    image_0.SaveAs(Server.MapPath(filePath));
                    WRMEDIASTORE mStore = new WRMEDIASTORE();
                    mStore.IDEntry = idEntry;
                    mStore.IDMedia = 1;
                    mStore.MediaName = "";
                    mStore.MediaPath = filePath;
                    mStore.CreateDate = DateTime.Now;
                    mStore.IDCreateBy = Int32.Parse(Session["userid"].ToString());
                    mStore.UpdateDate = (DateTime?) null;
                    mStore.IDUpdateBy = (int?) null;
                    mStore.Description = "";
                    mStore.Active = "N";
                    mStore.Keywords = "";
                    busWrmediastore._Add(mStore);
                }
                catch
                {
                }
            }
        }
        HttpPostedFile files1 = image_1.PostedFile;
        if (image_1.HasFile == false || files1.ContentLength > 500000)
        {
        }
        else
        {
            string _fileExt = Path.GetExtension(image_1.FileName);
            if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".png" || _fileExt.ToLower() == ".bmp" ||
                _fileExt.ToLower() == ".jpeg" || _fileExt.ToLower() == ".jpg")
            {
                try
                {
                    string filePath = "~/Images/Pic/" + DateTime.Now.Ticks.ToString() + "_" + Session["userid"].ToString() + _fileExt;
                    image_1.SaveAs(Server.MapPath(filePath));
                    WRMEDIASTORE mStore = new WRMEDIASTORE();
                    mStore.IDEntry = idEntry;
                    mStore.IDMedia = 1;
                    mStore.MediaName = "";
                    mStore.MediaPath = filePath;
                    mStore.CreateDate = DateTime.Now;
                    mStore.IDCreateBy = Int32.Parse(Session["userid"].ToString());
                    mStore.UpdateDate = (DateTime?)null;
                    mStore.IDUpdateBy = (int?)null;
                    mStore.Description = "";
                    mStore.Active = "N";
                    mStore.Keywords = "";
                    busWrmediastore._Add(mStore);
                }
                catch
                {
                }
            }
        }
        HttpPostedFile files2 = image_2.PostedFile;
        if (image_2.HasFile == false || files2.ContentLength > 500000)
        {
        }
        else
        {
            string _fileExt = Path.GetExtension(image_2.FileName);
            if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".png" || _fileExt.ToLower() == ".bmp" ||
                _fileExt.ToLower() == ".jpeg" || _fileExt.ToLower() == ".jpg")
            {
                try
                {
                    string filePath = "~/Images/Pic/" + DateTime.Now.Ticks.ToString() + "_" + Session["userid"].ToString() + _fileExt;
                    image_2.SaveAs(Server.MapPath(filePath));
                    WRMEDIASTORE mStore = new WRMEDIASTORE();
                    mStore.IDEntry = idEntry;
                    mStore.IDMedia = 1;
                    mStore.MediaName = "";
                    mStore.MediaPath = filePath;
                    mStore.CreateDate = DateTime.Now;
                    mStore.IDCreateBy = Int32.Parse(Session["userid"].ToString());
                    mStore.UpdateDate = (DateTime?)null;
                    mStore.IDUpdateBy = (int?)null;
                    mStore.Description = "";
                    mStore.Active = "N";
                    mStore.Keywords = "";
                    busWrmediastore._Add(mStore);
                }
                catch
                {
                }
            }
        }
        HttpPostedFile files3 = image_3.PostedFile;
        if (image_3.HasFile == false || files3.ContentLength > 500000)
        {
        }
        else
        {
            string _fileExt = Path.GetExtension(image_3.FileName);
            if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".png" || _fileExt.ToLower() == ".bmp" ||
                _fileExt.ToLower() == ".jpeg" || _fileExt.ToLower() == ".jpg")
            {
                try
                {
                    string filePath = "~/Images/Pic/" + DateTime.Now.Ticks.ToString() + "_" + Session["userid"].ToString() + _fileExt;
                    image_3.SaveAs(Server.MapPath(filePath));
                    WRMEDIASTORE mStore = new WRMEDIASTORE();
                    mStore.IDEntry = idEntry;
                    mStore.IDMedia = 1;
                    mStore.MediaName = "";
                    mStore.MediaPath = filePath;
                    mStore.CreateDate = DateTime.Now;
                    mStore.IDCreateBy = Int32.Parse(Session["userid"].ToString());
                    mStore.UpdateDate = (DateTime?)null;
                    mStore.IDUpdateBy = (int?)null;
                    mStore.Description = "";
                    mStore.Active = "N";
                    mStore.Keywords = "";
                    busWrmediastore._Add(mStore);
                }
                catch
                {
                }
            }
        }
    }
    
    protected void ddlArea_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlArea.SelectedValue == string.Empty)
        {
            ddlRegion.Items.Clear();
            ddlCity.Items.Clear();
            return;
        }
        ddlRegion.DataSource = busWrregion._GetList().Where(q => q.IDArea == Int32.Parse(ddlArea.SelectedValue)).Select(p => new
        {
            p.ID,
            p.RegionName
        }).ToList();
        ddlRegion.DataTextField = "RegionName";
        ddlRegion.DataValueField = "ID";
        ddlRegion.DataBind();
        ddlRegion.Items.Insert(0, new ListItem("---Select----", ""));
        ddlRegion.SelectedIndex = 0;
    }

    protected void ddlRegion_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlRegion.SelectedValue == string.Empty)
        {
            ddlCity.Items.Clear();
            return;
        }
        ddlCity.DataSource = busWrcity._GetList().Where(q => q.IDRegion == Int32.Parse(ddlRegion.SelectedValue)).Select(p => new
        {
            p.ID,
            p.CityName
        }).ToList();
        ddlCity.DataTextField = "CityName";
        ddlCity.DataValueField = "ID";
        ddlCity.DataBind();
        ddlCity.Items.Insert(0, new ListItem("---Select----", ""));
        ddlCity.SelectedIndex = 0;
    }
    
}